<?php

namespace App\Providers;

use Godruoyi\Snowflake\Snowflake;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use Godruoyi\Snowflake\RandomSequenceResolver;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('snowflake', function () {
            return (new Snowflake())
                ->setSequenceResolver(
                    new RandomSequenceResolver(time())
                );
        });
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Schema::defaultStringLength(191);

        Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
            return $validator->validateRegex($attribute, $value, ['/^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9])|(16[0-9])|(19[0-9]))\d{8}$/']);
        });
    }
}
